#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <stack>

using namespace std;

const int N = 2010;
int a[N][N];
map<char, int>mp;
vector<char> ch;

string r;
void OutString(string s)
{
	
	for (int k = 0; k < s.size(); k++)
	{
		if (s[k] != ' ')r += s[k];
		if (s[k] >= 'a' && s[k] <= 'z')ch.push_back(s[k]);
	}
	
}

void OutVariate(string s)
{
	//逻辑变量的输出
	sort(ch.begin(), ch.end()); //排序
	ch.erase(unique(ch.begin(), ch.end()), ch.end()); //去重
	for (auto e : ch) //遍历
	{
		cout << e << " ";
	}
	cout <<s<< endl;
	int t = 1, cnt;
	int len = ch.size();
	bool f;
	for (int i = 1; i <= len; i++)
	{
		cnt = 0;
		f = true;
		for (int j = 1; j <= (1 << len); j++)
		{
			if (f) {
				a[j][i] = 1;
				cnt++;
			}
			else {
				a[j][i] = 0;
				cnt++;
			}
			if (cnt == t) {
				f ^= 1; //异或
				cnt = 0;
			}
		}
		t = t * 2;
	}
}



//输出
int cal(int a, int b, char ch)
{
	if (ch == '|')
	{
		if (a == 0 && b == 0)return 0;
		else return 1;
	}
	else if (ch == '^')
	{
		if (a == 1 && b == 1)return 1;
		else return 0;
	}
	else if (ch == '-')
	{
		if (a == 1 && b == 0)return 0;
		else return 1;
	}
	else if (ch == '<')
	{
		if (a == b)return 1;
		else return 0;
	}
	return 0;
}



int OutFal(int num[15], int n, string s, vector<char> v)
{

	stack<int> opcal;
	stack<char> opt;
	for (int i = 0; i < s.length();)
	{
		if (s[i] >= 'a' && s[i] <= 'z')
		{
			for (int j = 0; j < n; j++)
			{
				if (s[i] == v[j]) opcal.push(num[n - j]);
			}
			i++;
			continue;
		}

		if (opt.empty() && (!(s[i] >= 'a' && s[i] <= 'z')))
		{
			opt.push(s[i]);
			if (s[i] == '|' || s[i] == '-')i += 2;
			else if (s[i] == '^' || s[i] == '!' || s[i] == '(' || s[i] == ')')i++;
			else if (s[i] == '<')i += 3;
			continue;
		}

		if (opcal.empty() && s[i] == '!')
		{
			opt.push(s[i]);
			i++;
			continue;
		}

		int flag = -1e9;
		if (opt.top() == '(' && s[i] == ')')flag = 0;
		else if (s[i] == ')')flag = 1;
		else if (opt.top() == '(')flag = -1;
		else if (s[i] == '(')flag = -1;
		else
		{
			if (mp[s[i]] > mp[opt.top()])flag = -1;
			else flag = 1;
		}

		if (flag == -1)opt.push(s[i]);
		else if (flag == 0)opt.pop();
		else if (flag == 1)
		{
			char ch = opt.top(); 
			opt.pop();
			if (ch == '!')opcal.top() = !opcal.top();
			else
			{
				int kb = opcal.top(); 
				opcal .pop();
				int ka = opcal.top(); 
				opcal.pop();
				opcal.push(cal(ka, kb, ch));
			}
		}

		if (flag == 1)continue;
		if ((s[i] == '|') || (s[i] == '-'))i += 2;
		else if (s[i] == '^' || s[i] == '!' || s[i] == '(' || s[i] == ')')i++;
		else i += 3;
	}

	while (!opt.empty())
	{
		char ch = opt.top();
		opt.pop();
		if (ch == '!')opcal.top() = !opcal.top();
		else
		{
			int kb = opcal.top(); opcal.pop();
			int ka = opcal.top(); opcal.pop();
			opcal.push(cal(ka, kb, ch));
		}
	}

	return opcal.top();
}




int main()
{
	//制定优先级
	mp['<'] = 1;
	mp['-'] = 2;
	mp['|'] = 3;
	mp['^'] = 4;
	mp['!'] = 5;

	string s;
	while (getline(cin, s))
	{

		OutString(s);
		OutVariate(s);
		int len = ch.size();
		for (int i = 1; i <= (1 << len); i++)
		{
			for (int j = len; j > 0; j--)
			{
				printf("%d ", a[i][j]); //最后一个打印换行
			}
			int x = solve(a[i], len, r, ch);
			printf("%d\n", x);//最后一个打印换行
		}

	}

	return 0;
}